package com.lywz.core.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * 
 */
@SuppressWarnings("unused")
public class Pagination {

    private int currentPage = 1;//当前页数,默认为第一页

    private int recordCount;//总记录条数

    private int pageCount;//总页数

    private int pageSize = 10;//每页记录条数

    private List<Integer> pageList; //将总页数改为list，便于前台使用

    /******************************* 构造函数 ****************************************/
    public Pagination() {
        setAll();

    }

    /**
     * 传入总记录条数，使用默认的每页显示条数
     * 
     * @param recordCount
     */
    public Pagination(int recordCount) {
        this.recordCount = recordCount;
        setAll();
    }

    /**
     * 传入总记录数，传入每页显示条数
     * 
     * @param recordCount
     * @param pageSize
     */
    public Pagination(int recordCount, int pageSize) {
        this.recordCount = recordCount;
        this.pageSize = pageSize;
        setAll();
    }

    //初始化分页相关属性
    public void setAll() {
        if (recordCount % pageSize == 0) {
            pageCount = recordCount / pageSize;
        } else {
            pageCount = (int) (recordCount / pageSize) + 1;
        }
    }

    /********************** 首页，上一页，下一页，末页 *****************************/
    private int firstPage;

    private int prevPage;

    private int nextPage;

    private int lastPage;

    public int getFirstPage() {
        return 1;
    }

    public void setFirstPage(int firstPage) {
        this.firstPage = firstPage;
    }

    public int getPrevPage() {
        return currentPage > 1 ? (currentPage - 1) : 1;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public int getNextPage() {
        return currentPage < pageCount ? (currentPage + 1) : pageCount;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getLastPage() {
        return pageCount;
    }

    public void setLastPage(int lastPage) {
        this.lastPage = lastPage;
    }

    /***************************************************************/

    public List<Integer> getPageList() {
        List<Integer> l = new ArrayList<Integer>();
        for (int i = 1; i <= pageCount; i++) {
            l.add(i);
        }
        return l;
    }

    public int getRecordCount() {
        return recordCount;
    }

    public int getPageCount() {
        return pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setCurrentPage(int currentPage) {
        if (currentPage < 1) currentPage = 1;
        else if (currentPage > pageCount) currentPage = pageCount;
        this.currentPage = currentPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }
}
